<div class="login-warp">
    <div class="login-inner">
        <div class="login-logo">
            <img src="/Extend/images/logo/login-logo.svg"/>
        </div>
        <div class="login-tip"></div>
        <div class="login-tr">
            <input class="inp inp-tel"  maxlength="11" placeholder="请输入电话号码" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
            <input class="get-code" type="button" value="获取验证码">
        </div>
        <div class="login-tr">
            <input class="inp inp-code" placeholder="请输入验证码" maxlength="6" onkeyup="this.value=this.value.replace(/[^\d]/g,'')">
        </div>
        <button class="login-btn" >立即登录</button>
    </div>
</div>
<script>
    $(".inp").focus(function(){
        $(this).closest(".login-tr").css("border-bottom","1px solid #CF1F57")
    }).blur(function(){
        $(this).closest(".login-tr").css("border-bottom","1px solid #ccc")
    })
    var role=$("#role").val();
    //获取验证码
    $(".get-code").click(function(){
        $(this).attr('disabled',true);
        $(this).addClass('notAllowed');
        var telephone=$(".inp-tel").val();
        console.log('/'+role+'/user/send',telephone)
        $.ajax({
            type: "POST",
            dataType: "json",
            url:'/'+role+'/user/send',
            data:{telephone:telephone},
            success: function (message){
                if(message.code==1){
                    $('.get-code').attr('disabled',true);
                    $(".login-tip").text('校验码发送成功');
                    var count = 60;
                    var resend = setInterval(function(){
                        if (count >=0){
                            $('.get-code').addClass('notAllowed');
                            $('.get-code').val(count+'秒后重新发送');
                        }else {
                            clearInterval(resend);
                            $('.get-code').attr('disabled',false);
                            $('.get-code').removeClass('notAllowed');
                            $('.get-code').val('获取校验码');
                        }
                        count--;
                    }, 1000);
                }
                else {
                    $('.get-code').attr('disabled',false);
                    $(".login-tip").text(message.message);
                }
            }
        });
    });

    // 用户登录
    $(".login-btn").click(function(){
        var telephone = $(".inp-tel").val();
        var code = $(".inp-code").val();
        $.ajax({
            type: "POST",
            dataType: "json",
            url:'/'+role+'/user/login',
            data:{telephone:telephone,code:code},
            success: function (message){
                if(message.code== 1){
                    window.location.href='/'+role+'/index/index';
                }else{
                    $(".login-tip").text(message.message);
                }
            }
        });
    });
</script>
<style>
    /*登录 start*/
    .login-warp{
        position: fixed;
        top: 0px;
        right: 0px;
        bottom: 0px;
        left: 0px;
        min-width: 1200px;
        margin: auto;
        background:#fff url("/Extend/images/login-bg.png") no-repeat center center;
        background-size:cover;
    }
    .login-inner{
        position: absolute;
        top: 0px;
        bottom: 0px;
        left: 350px;
        right: -350px;
        width: 325px;
        height: 385px;
        padding: 53px 44px;
        box-sizing: border-box;
        background: #fff;
        box-shadow: 0px 0px 10px rgba(0,0,45,0.2);
        border-radius: 6px;
        margin: auto;
        overflow: hidden;
    }
    .login-logo{
        width: 132px;
        height: 64px;
        margin: 0 auto;
    }
    .login-logo>img{
        width:100%;
        height:100%;
    }
    .login-tip{
        height: 20px;
        line-height: 20px;
        text-align: center;
        font-size: 12px;
        color: #999;
        margin-top: 15px;
    }
    .login-tr{
        width: 100%;
        height: 30px;
        display: flex;
        flex-direction: row;
        border-bottom: 1px solid #ccc;
        padding-left: 10px;
        box-sizing: border-box;
        margin-top: 20px;
    }
    .inp{
        width: 140px;
        height: 30px;
        line-height: 30px;
        font-size: 14px;
        color: #666;
        border: none;
        background: transparent;
    }
    .get-code{
        width: 100px;
        font-size: 12px;
        color: #999;
        height: 22px;
        line-height: 22px;
        text-align: center;
        background:#f3f3f3;
        border-radius: 25px!important;
        cursor: pointer;
    }
    .login-btn{
        width:100%;
        height: 30px;
        text-align: center;
        line-height: 30px;
        border-radius: 4px;
        background: #cf1f57;
        color: #fff;
        font-size: 14px;
        letter-spacing: 2px;
        cursor: pointer;
        margin-top: 45px;
    }
    .notAllowed{
        cursor:not-allowed;
    }
    /*登录 end*/
</style>
